async function get_openid_by_cloud_db (){
  const DB = wx.cloud.database()
  const collection_login_info = "login_info"
  let coll;
  coll=DB.collection(collection_login_info)
  // 发送一条消息去数据库，拿到返回的_id
  let res_with_id = await coll.add({
    data:{
      messages:"login"
    }
  })
  // 通过返回的_id 去拿 _openid
  let res_with_openid = await coll.where({
      _id:res_with_id._id
  }).get()
  // 登录完自动删除了登录记录
  let _openid=res_with_openid.data[0]._openid
  //console.log("openid",_openid)
  let all_record=await coll.where({_openid:_openid}).get()
  //console.log(all_record)
  let message = await coll.where({_openid:_openid}).remove()
  return _openid
}
async function get_openid(){
  try{
    let local_openid=await wx.getStorage({key:'_openid'})
    return local_openid.data
  }catch(err){
    console.log("err is",err)
      let web_openid = await get_openid_by_cloud_db()
      let message = await wx.setStorage({
        key: '_openid',
        data: web_openid,
      });
      console.log(message)
      return web_openid
  }
}
module.exports = {
  get_openid: get_openid
}